#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import logging

import allure
import pytest
from utils.sign import get_sign
import json

@pytest.fixture(autouse=True)
def set_feature(paged,naviBar,pre_login,state_file):
    allure.dynamic.feature('我的自选')
    # 自动登录
    # with paged._page.expect_response(f'/api/data/site/auth_login') as res:
    #     paged.goto(url)

    # res=res.value
    # token=res.json()['result']['data']['token']

    # 读取浏览器登录状态
    pre_login()
    localStorage=paged.context.storage_state()
    tokenJson=localStorage['origins'][0]['localStorage'][-1]['value']
    token=json.loads(tokenJson)['value']

    # 重置关注列表
    apiPath = '/api/data/site/update_user_collect'
    defaultSubscribe=["001339", "600031", "601188", "300225","300957","301337","000679","300405","603628",
                      "688390", "688717", "002786", "300093", "300237","603004","603333","603392","603530","002347",
                      "300538",'003005','000001','000333','301525','000338']
    # 设置默认的订阅股票列表
    data = {
        "action": "update",
        "stock_code": defaultSubscribe
    }
    sign = get_sign(data)
    headers={
        "Signature":sign,
        "Authorization":f"Bearer {token}"
    }

    res=paged.request.post(apiPath, data=data,headers=headers)
    assert res.ok
    assert res.json()['errcode']==0,res.json()

    naviBar.subscribeButton.click()



